import numpy as np
from Functions.Miscellaneous import utils as ut



def make_strategy(Y, scaler_type, strategy_type):
    X = Y.copy()
    if scaler_type == 'relative':
        #== Divide by the total number of initiatives
        scaler_I = ut.utils().return_Initiatives()
        scaler_ = X[scaler_I].sum(axis = 1)

    elif scaler_type == 'intensity':
        scaler_ = X.capx_usd.apply(np.log)

    if strategy_type == 'Total':
        tot = ut.utils().return_Initiatives()
        tot.remove('pricing')
        X['Strategy'] = X[tot].sum(axis = 1) #/X.capx_usd.apply(np.log)
    if strategy_type == 'Innovation':
        target_initiatives=  ['r&d investments', 'new products', 'association', 'organizational structuring'] 
        X['Strategy'] = X[target_initiatives].sum(axis = 1)/scaler_
    elif strategy_type == 'Risk mitigation':
        target_initiatives =  ['modification of procedures', 'asset modification', 'training',  'assessment and measurement', 'adoption of standards and rules']
        X['Strategy'] = X[target_initiatives].sum(axis = 1)/scaler_
    elif strategy_type == 'Stakeholders engagement':
        target_initiatives =  ['donation & funding', 'communication', 'volunteerism', 'incentives', 'pricing']
        X['Strategy'] = X[target_initiatives].sum(axis = 1)/scaler_
    return X[['Strategy', 'mrg']]